/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-03-18 20:45:03
 * @LastEditors: voanit
 * @LastEditTime: 2022-03-19 15:29:37
 */
import React from 'react'
import './MyFooter.css'
export default function MyFooter({ changeAll, flag, list }) {
  console.log(flag, 57687)
  const total = () =>
    list
      .filter((item) => item.goods_state)
      .reduce((sum, item2) => sum + item2.goods_price * item2.goods_count, 0)
  const countAll = () =>
    list
      .filter((item) => item.goods_state)
      .reduce((sum, item2) => sum + item2.goods_count, 0)

  return (
    <div className="my-footer">
      <div className="custom-control custom-checkbox">
        <input
          type="checkbox"
          className="custom-control-input"
          id="footerCheck"
          checked={flag}
          onChange={() => changeAll(!flag)}
        />
        <label className="custom-control-label" htmlFor="footerCheck">
          全选
        </label>
      </div>
      <div>
        <span>合计:</span>
        <span className="price">¥ {total()}</span>
      </div>
      <button type="button" className="footer-btn btn btn-primary">
        结算 ({countAll()})
      </button>
    </div>
  )
}
